package com.cg.springboot.mapper;

import com.cg.springboot.entity.Book;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @program: springboot->BookMapper
 * @author: cg
 * @create: 2022-04-27 10:57
 **/
@Component
@Mapper
public interface BookMapper {

    /**
     * 获取所有书籍
     * @return
     */
    @Select("select * from book")
    List<Book> getAllBook();

    /**
     * 通过id获取书籍
     * @param id
     * @return
     */
    @Select("select * from book where bookID=#{id}")
    Book getBookById(Integer id);

    /**
     * 添加书籍
     * @param book
     */
    @Insert("insert into book(bookName, bookPrice) values(#{bookName},#{bookPrice})")
    void insertBook(Book book);

    /**
     * 通过id删除书籍
     * @param id
     */
    @Delete("delete from book where bookID=#{id}")
    void deleteBookById(Integer id);

}
